package com.io.model;

import com.io.config.WrapInt;
import com.io.protocol.CommandConstants;
import io.netty.buffer.ByteBuf;

/**
 * Created by yangyx on 2016/7/27.
 * 实时数据上报
 */
public class RealtimeRptReq extends BaseModel{

    public int rtLongitude;     //实时经度
    public int rtLatitude;      //实时纬度
    public short rtVelocity;    //实时速度
    public short rtAltitude;    //实时海拔
    public short rtDirection;   //实施朝向

    public byte ftYear;         //起始帧时间:年
    public byte ftMonth;        //起始帧时间:月
    public byte ftDay;          //起始帧时间:日
    public byte ftHour;         //起始帧时间:时
    public byte ftMinute;       //起始帧时间:分
    public byte ftSecond;       //起始帧时间:秒
    public byte ftMillisecond;  //起始帧时间:1/100秒

    private int dataSectionNum; //数据段数量

    public RealTime data;  //主体数据

    public static final int minLength=22;//最小长度

    /**
     * byteBuf转实体
     * @param buf
     * @param leftContentLength
     * @return
     */
    public static RealtimeRptReq fromByteBuf(ByteBuf buf, int leftContentLength) {
        if(leftContentLength<minLength){
            return null;
        }else{
            //填充数据
            RealtimeRptReq realtimeRptReq=new RealtimeRptReq();
            realtimeRptReq.rtLongitude = buf.readInt();
            realtimeRptReq.rtLatitude = buf.readInt();
            realtimeRptReq.rtVelocity = buf.readShort();
            realtimeRptReq.rtAltitude = buf.readShort();
            realtimeRptReq.rtDirection = buf.readShort();
            realtimeRptReq.ftYear = buf.readByte();
            realtimeRptReq.ftMonth = buf.readByte();
            realtimeRptReq.ftDay = buf.readByte();
            realtimeRptReq.ftHour = buf.readByte();
            realtimeRptReq.ftMinute = buf.readByte();
            realtimeRptReq.ftSecond = buf.readByte();
            realtimeRptReq.ftMillisecond = buf.readByte();
            realtimeRptReq.dataSectionNum = buf.readUnsignedByte();

            realtimeRptReq.data=new RealTime();

            int lenLeft=leftContentLength-minLength;
            for(int i=0;i<realtimeRptReq.dataSectionNum;i++){
                if(lenLeft>0){
                    byte dsClass=buf.readByte();
                    lenLeft -= 1;
                    WrapInt realtimeDs;
                    switch (dsClass){
                        case CommandConstants.DscVehicleCommon:

                            break;





                    }
                }
            }








            return null;
        }
    }
}
